<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑项目付款</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="enginid" readonly>
                            <input type="text" id="enginid_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">委托方</label>
                        <div class="layui-input-block">
                            <input type="text" id="lian_unit" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目资金情况</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">施工合同金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="shimoney" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计收款金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="incomeenginfee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计付款(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="payenginfee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计扣款(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="neikoufee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">累计项目费用报销(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="paybaofee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计结算支付(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="payment_xiangfu" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目余额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="balance" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计待扣(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="leikoudai" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目可用余额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="shengjiefee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>











            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>本次支付信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>付款编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项类型</label>
                        <div class="layui-input-block">
                            <div id="feitype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项摘要</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhai" id="zhai" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>付款依据</label>
                        <div class="layui-input-block">
                            <select id="yiju" name="yiju" lay-filter="yiju">
                                <option value="">无</option>
                                <option value="cai">采购合同</option>
                                <option value="jie">合同结算单</option>
                            </select>
                            <p class="error" id="yiju_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide yiju_cai">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>依据名称(采购合同)</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="caiid" class="layui-input caiid" onclick="choose_contract_cai()">
                            <div class="choose_div" id="caiid" key="1"></div>
                            <span class="choose_one" onclick="choose_contract_cai()"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide yiju_jie">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>依据名称(合同结算单)</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="jieid" class="layui-input jieid" onclick="choose_contract_cai_jie()">
                            <div class="choose_div" id="jieid" key="1"></div>
                            <span class="choose_one" onclick="choose_contract_cai_jie()"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>



            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>请款金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" placeholder="请输入" autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>发票情况</label>
                        <div class="layui-input-block">
                            <div id="incqing"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>支付方式</label>
                        <div class="layui-input-block">
                            <div id="incdaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>付款对象</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="gonger" class="layui-input gonger" onclick="openPage('../public/choose_dealcom.php?dom=gonger&page=payment_engin','80%','80%')">
                            <div class="choose_div" id="gonger" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=gonger&page=payment_engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">账户+账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="banknum" id="banknum" placeholder="请填写对方账户及账号：张三（123456789000000）" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开户行</label>
                        <div class="layui-input-block">
                            <input type="text" name="bankname" id="bankname" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>



    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            zhai: {required: true},
            money: {required: true},
        },
        messages:{
            zhai: {required: "请输入"},
            money: {required: "请输入"},
        }
    });

    function choose_contract_cai(){
        var enginid = $("#enginid").val();
        if(!enginid){
            facade.error("请先选择项目");return false;
        }
        openPage('../public/choose_contract_cai.php?dom=caiid&page=payment_engin&enginid='+enginid,'80%','80%')
    }

    function choose_contract_cai_jie(){
        var enginid = $("#enginid").val();
        if(!enginid){
            facade.error("请先选择项目");return false;
        }
        openPage('../public/choose_contract_cai_jie.php?dom=jieid&page=payment_engin&enginid='+enginid,'80%','80%')
    }

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_payment_engin_edit,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                var engininfo = res.data.engininfo;
                if(engininfo){
                    $("#enginid" ).val(engininfo.id);
                    $("#enginid_name" ).val(engininfo.name);
                    $("#lian_unit" ).val(engininfo.lian_unit);
                    $("#shimoney" ).val(engininfo.shimoney);
                    $("#incomeenginfee" ).val(engininfo.incomeenginfee || 0);
                    $("#payenginfee" ).val(engininfo.payenginfee);
                    $("#paybaofee" ).val(engininfo.paybaofee);
                    $("#neikoufee" ).val(engininfo.neikoufee);
                    $("#payment_xiangfu" ).val(engininfo.payment_xiangfu);
                    $("#balance" ).val(engininfo.balance);
                    $("#leikoudai" ).val(engininfo.leikoudai);
                    $("#shengjiefee" ).val(engininfo.shengjiefee);
                }

                if(data.yiju == 'cai'){
                    var caiinfo = res.data.caiinfo;
                    if(caiinfo){
                        set_choose_btn('caiid',caiinfo.id, '采购合同-(金额：'+caiinfo.money+')');
                    }
                    $(".yiju_cai").removeClass('layui-hide');
                    $(".yiju_jie").addClass('layui-hide');
                }else if(data.yiju == 'jie'){
                    var jieinfo = res.data.jieinfo;
                    if(jieinfo){
                        set_choose_btn('jieid',jieinfo.id, '合同结算单-(金额：'+jieinfo.money+')');
                    }
                    $(".yiju_cai").addClass('layui-hide');
                    $(".yiju_jie").removeClass('layui-hide');
                }else{
                    $(".yiju_cai").addClass('layui-hide');
                    $(".yiju_jie").addClass('layui-hide');
                }




                $("#yiju").val(data.yiju);
                $("#number").val(data.number);
                $("#zhai").val(data.zhai);
                $("#money").val(data.money);
                $("#banknum").val(data.banknum);
                $("#bankname").val(data.bankname);
                $("#explain").val(data.explain);

                xmselect_dan('feitype', res.data.feitype, data.feitype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#feitype").find('xm-select').removeClass('error');
                    }else{
                        $("#feitype").find('xm-select').addClass('error');
                    }
                });

                xmselect_dan('incqing', res.data.incqing, data.incqing, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#incqing").find('xm-select').removeClass('error');
                    }else{
                        $("#incqing").find('xm-select').addClass('error');
                    }
                });
                xmselect_dan('incdaotype', res.data.incdaotype, data.incdaotype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#incdaotype").find('xm-select').removeClass('error');
                    }else{
                        $("#incdaotype").find('xm-select').addClass('error');
                    }
                });

                if(data.gonger){
                    set_choose_btn('gonger',data.gonger,data.gonger);
                }



                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_from();
                initParseMoney();
            }
        });

        form.on('select(yiju)', function(data){
            if(data.value == 'cai'){
                $(".yiju_cai").removeClass('layui-hide');
                $(".yiju_jie").addClass('layui-hide');
            }else if(data.value == 'jie'){
                $(".yiju_cai").addClass('layui-hide');
                $(".yiju_jie").removeClass('layui-hide');
            }else{
                $(".yiju_cai").addClass('layui-hide');
                $(".yiju_jie").addClass('layui-hide');
            }
        });


        form.on('submit(add)', function(data){


            data.field.caiid = get_choose_val('caiid');
            data.field.jieid = get_choose_val('jieid');
            data.field.gonger = get_choose_val('gonger');
            var validRes = $("#commentForm").valid();


            if(data.field.yiju == 'cai'){
                formValid('caiid');
                if(data.field.caiid == undefined || !data.field.caiid){
                    validRes = false;
                }
            }
            if(data.field.yiju == 'jie'){
                formValid('jieid');
                if(data.field.jieid == undefined || !data.field.jieid){
                    validRes = false;
                }
            }





            if(!data.field.feitype){
                $("#feitype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#feitype").find('xm-select').removeClass('error');
            }

            if(!data.field.incqing){
                $("#incqing").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#incqing").find('xm-select').removeClass('error');
            }
            if(!data.field.incdaotype){
                $("#incdaotype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#incdaotype").find('xm-select').removeClass('error');
            }

            formValid('gonger');
            if(data.field.gonger == undefined || !data.field.gonger){
                validRes = false;
            }

            if(!validRes){return false;}


            // data = parseMoney(data);
            // var shengjiefee = parseValidNum($("#shengjiefee").val()) || 0;
            // if(data.field.money > shengjiefee){
            //     facade.error("请款金额不能大于项目可用余额");return false;
            // }




            data = parseMoney(data);
            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');

            facade.ajax({url: ask_payment_engin_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });
            return false;
        });

    });



</script>
</body>
</html>
